package com.foreveross.util;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.res.Resources;
import android.view.Window;
import android.widget.TextView;

import com.foreveross.chameleon.R;

public final class DialogUtils {
	private static final String TAG="DialogUtils";
	private static Builder builder;
	

	public static Dialog getDialog(Context context, int layoutId) {
		Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(layoutId);
		return dialog;
	}

	public static AlertDialog getAlertDialog(Context context, int title, int msg, int ok, int cancel) {
		Resources resources = context.getResources();
		builder = new AlertDialog.Builder(context);
		builder.setTitle(resources.getString(title));
		builder.setMessage(resources.getString(msg));
		if (resources.getString(ok) != null) {
			builder.setPositiveButton(resources.getString(ok), new DialogInterface.OnClickListener() {

				@Override
				public void onClick(DialogInterface dialog, int which) {
					builder.create().dismiss();
				}

			});
		}
		if (resources.getString(cancel) != null) {
			builder.setNegativeButton(resources.getString(cancel), new DialogInterface.OnClickListener() {

				@Override
				public void onClick(DialogInterface dialog, int which) {
					builder.create().dismiss();
				}
			});
		}
		return builder.create();
	}

	public static AlertDialog getAlertDialog(Context context, String title, String message, String ok,String cancel,OnClickListener okListener,OnClickListener cancelListener) {
		
		Builder tipsbuilder = new AlertDialog.Builder(context);
		if (title != null) {
			tipsbuilder.setTitle(title);
		}
		tipsbuilder.setMessage(message);
		if(ok!=null){
			tipsbuilder.setPositiveButton(ok, okListener);
		}
		if(cancel!=null){
			tipsbuilder.setNegativeButton(cancel, cancelListener);
		}
		return tipsbuilder.create();
		
	}
	
	public static Dialog showloadingDialog(Context context,String loadingTxt){
		Dialog dialog = new Dialog(context,R.style.common_dialog);
		dialog.setContentView(R.layout.dialog_layout);
		TextView tx=(TextView) dialog.findViewById(R.id.dialog_text);
		if(loadingTxt!=null){
			tx.setText(loadingTxt);
		}
		return dialog;
	}
}
